package org.myy.learn.hot.贪心算法;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class 跳跃游戏 {

    public static boolean canJump(int[] nums) {
        int n = nums.length;
        int rightmost = 0;
        for (int i = 0; i < n; i++) { //ToDo 其中的i++和++i没区别
            if (i <= rightmost) {     //ToDo 终止条件
                rightmost = Math.max(rightmost, i + nums[i]);
                if (rightmost >= n - 1) {  //ToDo 下标是len - 1
                    return true;
                }
            }
        }
        return false;
    }


    public static void main(String[] args) {
        int[] nums = new int[]{3,2,1,0,4};
        boolean flag = canJump(nums);
        log.info("执行结束，是否达到={}", flag);
    }
}
